import { _decorator, Component, Node } from 'cc';
import { Holder, IElement, ScrollAdapter, View } from '../../libs/adapter';
import { Prefab } from 'cc';
import { Item } from './Item';
const { ccclass, property } = _decorator;
export interface ICardModel {
    name: string
}
@ccclass('Adapter')
export class Adapter extends ScrollAdapter<ICardModel> {

    @property(Node)
    prefab: Node = null!

    public getPrefab(data: ICardModel): Node | Prefab {
        return this.prefab
    }
    public getHolder(node: Node, code: string): Holder<ICardModel> {
        return new MyHolder(node, code, this)
    }
    public getView(): View<ICardModel> {
        return new MyView(this)
    }
    public initElement(element: IElement, data: ICardModel) {
    }

    start() {
        var list = []
        for (let i = 0; i < 100; i++) {
            list.push({ name: i + "" })
        }
        this.modelManager.insert(list)
    }

    update(deltaTime: number) {

    }
}

class MyView extends View<ICardModel> {
    protected onVisible(): void {
    }
    protected onDisable(): void {
    }
}
class MyHolder extends Holder<ICardModel> {
    private _item: Item | null = null
    protected onCreated(): void {
        this._item = this.node.getComponent(Item)
    }
    protected onVisible(): void {
        this._item?.show(this)
    }
    protected onDisable(): void {
        this._item?.hide()
    }
}
